package pro.spring.service;

import java.util.List;
import pro.spring.inter.UsersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pro.spring.inter.InformationMapper;
import pro.spring.inter.UcollectMapper;
import pro.spring.model.Ucollect;
import pro.spring.vo.PaginationVo;

@Service
public class UcollectService {
	
	@Autowired
	private UcollectMapper UcollectMapper;
	
	@Autowired
	private InformationMapper InformationMapper;
	
	@Autowired
	private UsersMapper UsersMapper;
	
	public PaginationVo<Ucollect> getcollByUid(Integer uid,Integer type,int pagenum,int pagesize){
		//int pagenum是当前的页码,int pagesize是每页显示的数据数量
		PaginationVo<Ucollect> pageVo=new PaginationVo<Ucollect>();
		//一定要在setPageCount()方法之后执行setPageNum
		pageVo.setCount(UcollectMapper.selectCountByUid(uid,type));
		pageVo.setRows(pagesize);
		pageVo.setPageNum(pagenum);
		List<Ucollect> li = UcollectMapper.selectByUid(uid,type,pageVo.getOffset(), pageVo.getRows());
		for(Ucollect th:li){
			Integer uId = InformationMapper.selectByPrimaryKey(th.getInformationInId()).getUsersUId();
			th.setUser(UsersMapper.selectByPrimaryKey(uId));
		}
		pageVo.setList(li);
		return pageVo;
	}
	
}
